package br.com.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name="tb_usuario")
public class Usuario extends Domain {
	
	/**************************************************************************/
	/**                             ATRIBUTOS                                **/
	/**************************************************************************/
	
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY) 
	@Column         (name="idUsuario")
	private Integer id;
	
    @NotEmpty
	@Size    
	@Column   (name="nome", length=70)
	private String nome;    
    
    @NotEmpty 
	@Size    
	@Column   (name="login", length=20)
	private String login;
	
    @NotEmpty 
	@Size     
	@Column   (name="senha", length=200)
	private String senha;
    
    @Column(name="is_alterar_senha", columnDefinition="BOOLEAN")
   	private Boolean alterarSenha;
    
    @Column(name="fixo")
	private Boolean fixo;
    
    /********************************************************************/
	/**                       RELACIONAMENTOS         				   **/
	/********************************************************************/
   
    @NotNull 
	@JoinColumn (name = "idPerfil")
	@OneToOne   (fetch=FetchType.EAGER)
	private Perfil perfil;
    
    /********************************************************************/
	/**                           TRANSIENTS        				   **/
	/********************************************************************/
    
    @Transient
	private String senhaAtual;
    
	@Transient
	private String senhaNova;
	
	@Transient
	private String senhaConfirmar;
	
	@Transient
	private String senhaBanco;
	
	
	/********************************************************************/
	/**                          GET's E SET's                         **/
	/********************************************************************/
	
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getSenha() {
		if (senha == null)
			senha = "";
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public Boolean getAlterarSenha() {
		return alterarSenha;
	}

	public void setAlterarSenha(Boolean alterarSenha) {
		this.alterarSenha = alterarSenha;
	}

	public Perfil getPerfil() {
		return perfil;
	}

	public void setPerfil(Perfil perfil) {
		this.perfil = perfil;
	}

	public String getSenhaConfirmar() {
		if (senhaConfirmar == null)
			senhaConfirmar = "";
		return senhaConfirmar;
	}

	public void setSenhaConfirmar(String senhaConfirmar) {
		this.senhaConfirmar = senhaConfirmar;
	}

	public String getSenhaNova() {
		if (senhaNova == null)
			senhaNova = "";
		return senhaNova;
	}

	public void setSenhaNova(String senhaNova) {
		this.senhaNova = senhaNova;
	}
	
	public Boolean getFixo() {
		return fixo;
	}

	public void setFixo(Boolean fixo) {
		this.fixo = fixo;
	}
	
	public String getSenhaAtual() {
		return senhaAtual;
	}

	public void setSenhaAtual(String senhaAtual) {
		this.senhaAtual = senhaAtual;
	}
	
	public String getSenhaBanco() {
		return senhaBanco;
	}

	public void setSenhaBanco(String senhaBanco) {
		this.senhaBanco = senhaBanco;
	}

	/********************************************************************/
	/**                EQUALS E HASH CODE  - RETIRAR LIST's            **/
	/********************************************************************/
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((alterarSenha == null) ? 0 : alterarSenha.hashCode());
		result = prime * result + ((fixo == null) ? 0 : fixo.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((login == null) ? 0 : login.hashCode());
		result = prime * result + ((nome == null) ? 0 : nome.hashCode());
		result = prime * result + ((perfil == null) ? 0 : perfil.hashCode());
		result = prime * result + ((senha == null) ? 0 : senha.hashCode());
		result = prime * result
				+ ((senhaAtual == null) ? 0 : senhaAtual.hashCode());
		result = prime * result
				+ ((senhaConfirmar == null) ? 0 : senhaConfirmar.hashCode());
		result = prime * result
				+ ((senhaNova == null) ? 0 : senhaNova.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Usuario other = (Usuario) obj;
		if (alterarSenha == null) {
			if (other.alterarSenha != null)
				return false;
		} else if (!alterarSenha.equals(other.alterarSenha))
			return false;
		if (fixo == null) {
			if (other.fixo != null)
				return false;
		} else if (!fixo.equals(other.fixo))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (login == null) {
			if (other.login != null)
				return false;
		} else if (!login.equals(other.login))
			return false;
		if (nome == null) {
			if (other.nome != null)
				return false;
		} else if (!nome.equals(other.nome))
			return false;
		if (perfil == null) {
			if (other.perfil != null)
				return false;
		} else if (!perfil.equals(other.perfil))
			return false;
		if (senha == null) {
			if (other.senha != null)
				return false;
		} else if (!senha.equals(other.senha))
			return false;
		if (senhaAtual == null) {
			if (other.senhaAtual != null)
				return false;
		} else if (!senhaAtual.equals(other.senhaAtual))
			return false;
		if (senhaConfirmar == null) {
			if (other.senhaConfirmar != null)
				return false;
		} else if (!senhaConfirmar.equals(other.senhaConfirmar))
			return false;
		if (senhaNova == null) {
			if (other.senhaNova != null)
				return false;
		} else if (!senhaNova.equals(other.senhaNova))
			return false;
		return true;
	}
	
	
	
}
